<template>
  <div class="pagss">
    <Navv></Navv>

    <el-row :gutter="20">


      <el-col :span="4">
        <!-- 侧边导航++++++++++++++++++++++ -->
        <Sidebar defaultActive='5-1'></Sidebar>
        <!-- 侧边导航=============== -->
      </el-col>`


      <el-col :span="20">
        <div class="panel-group1">
          <el-form label-width="100px" class="demo-ruleForm">

            <el-form-item style="width: 300px;" label="用户名：">
              <div class="row_a_c">
                <el-input v-model="username"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改</div>
              </div>
            </el-form-item>

            <el-form-item style="width: 300px;" label="修改头像：">


              <el-upload :action="upload_url" :headers="headers" :before-upload="handleSetHeaders"
                :on-success="handleFileSuccess" :show-file-list="false" class="avatar-uploader">




                <div class="row center" style="position: relative;">

                  <div>

                    <div class="tximg column center">
                      <img style="height: 78px;width: 90px;" v-if="avatar" :src="avatar" class="avatar">
                      <img v-else style="height: 78px;width: 90px;" src="@/assets/images/tx.png" />
                      <div class="mt_5 f_14 color_878787">上传头像</div>
                    </div>


                    <div class="mt_5" style="width: 260px;">(支持200kb以下的JPG、PNG格式的图片)</div>
                  </div>

                  <div style="position: absolute;left: 180px;" class="cursor">
                    <el-button type="primary" @click="updateUser()">保存头像</el-button>
                  </div>

                </div>

              </el-upload>
            </el-form-item>

            <el-form-item style="width: 300px;" label="手机绑定：">
              <div class="row_a_c">
                <el-input v-model="mobile"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改</div>
              </div>
            </el-form-item>


            <el-form-item style="width: 300px;" label="QQ绑定：">
              <div class="row_a_c">
                <el-input v-model="qq"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改</div>
              </div>
            </el-form-item>


            <el-form-item style="width: 300px;" label="微信绑定">
              <div class="row_a_c">
                <el-input v-model="weixin"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改</div>
              </div>
            </el-form-item>

          </el-form>
        </div>
      </el-col>
    </el-row>














  </div>
</template>

<script>
  import CountTo from 'vue-count-to'
  import Cookies from 'js-cookie'
  import Vue from 'vue';
  import Navv from "@/components/Navv";
  import Sidebar from "@/components/Sidebar";
  import * as User from "@/api/system/user";
  import * as Auth from '@/utils/auth'

  export default {
    username: 'Index',
    components: {
      CountTo,
      Navv,
      Sidebar

    },
    data() {
      return {
        avatar: '',
        username: '',
        mobile: '',
        qq: '',
        weixin: '',

        upload_url: process.env.VUE_APP_BASE_URL + "/file/upload",
        headers: Auth.getHeader(),
      }
    },
    created() {
      this.getUserInfo(); //查询用户详情
    },
    mounted() {

    },
    methods: {

      handleSetHeaders() {
        this.headers = Auth.getHeader();
      },
      /****文件上传*****/
      handleFileSuccess(res) {
        this.avatar = res.data;
      },


      /**查询用户详情 */
      getUserInfo() {
        //audit_status 1：未提交，2：已提交 3：审核通过 4：审核失败'
        this.loading = true;
        User.getUserInfo().then(response => {

          this.avatar = response.data.avatar
          this.username = response.data.username
          this.mobile = response.data.mobile
          this.qq = response.data.qq
          this.weixin = response.data.weixin


          console.log('用户详情', response.data)
          this.loading = false;
        });
      },

      updateUser() {

        if (!this.username) {
          this.$message({
            message: '用户名不能为空',
            type: 'warning'
          });
          return

        }
        if (!this.mobile) {
          this.$message({
            message: '手机号不能为空',
            type: 'warning'
          });
          return
        }

        var per = {
          avatar: this.avatar,
          username: this.username,
          mobile: this.mobile,
          qq: this.qq,
          weixin: this.weixin,
        }

        User.updateUser(per).then((data) =>{
          this.$modal.msgSuccess("修改成功");
            //处理成功后的逻辑
            console.log(data);//这个data 是接收的resolve参数--
        }).catch((err) =>{
            console.log(err);
        })
      },


      toUrl(url) {
        this.$router.push(url);
      },



    }
  }
</script>

<style lang="scss" scoped>
  .pagss {
    height: 100%;
    background: #f4f6f9;
    // padding: 5px 0 15px 40px;
  }

  .panel-group1 {
    padding: 25px;
    margin-top: 18px;
    margin-bottom: 0px;
    margin-right: 15px;
    min-height: 760px;
    background: #FFFFFF;
    border-radius: 10px 10px 10px 10px;
    opacity: 1;
  }

  .tximg {
    width: 150px;
    height: 150px;
    background: #FFFFFF;
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
    border: 1px solid #BBBBBB;
  }
</style>
